<!DOCTYPE html>
<html lang="zh">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>
    
    ES6 模板字符串 - DSRBLOG
    
  </title>
  

  
  
  <link href="atom.xml" rel="alternate" title="DSRBLOG" type="application/atom+xml">
  <link rel="stylesheet" href="asset/css/style.min.css">
  <link rel="stylesheet" href="asset/css/doc.css">
  <script src="asset/app.js"></script>


</head>

<body> <section class="ct-body">
	<div class="container">
		<div class="columns is-variable bd-klmn-columns is-4 is-centered">
			<div class="column is-four-fifths">
				<div class="post-body single-content">
					
					<h1 class="title">
						ES6 模板字符串
					</h1>


					<div class="media">
						
						
						<div class="media-content">
							<div class="content">
								<p>
									<span class="date">2022/07/04 00:01 上午</span>
									

									

									<br />
									<span class="tran-tags">Tags:</span>&nbsp;
									
									<a class="tag is-link is-light">#ES6新特性</a>
									

								</p>
							</div>
						</div>

					</div>
				</div>
				<article class="markdown-body single-content">
					<p>ES6引入了新的声明字符串的方式：<code>``</code></p>
<h2><a id="%E5%A3%B0%E6%98%8E" class="anchor" aria-hidden="true"><span class="octicon octicon-link"></span></a>声明</h2>
<pre class="line-numbers"><code class="language-js">let str = `这是一个字符串`;
console.log(str); //输出 '这是一个字符串'
</code></pre>
<h2><a id="%E7%89%B9%E6%80%A7" class="anchor" aria-hidden="true"><span class="octicon octicon-link"></span></a>特性</h2>
<ol>
<li>内容中可以直接出现换行符</li>
</ol>
<pre class="line-numbers"><code class="language-js">let str = `
    &lt;ul&gt;
        &lt;li&gt;Kafu&lt;/li&gt;
        &lt;li&gt;Ling&lt;/li&gt;
    &lt;/ul&gt;
`
</code></pre>
<ol start="2">
<li>变量拼接</li>
</ol>
<pre class="line-numbers"><code class="language-js">    let kafu = '卡夫';
    let say = `${kafu}说R6打不过就是对面开挂`;
    
    console.log(say); //输出 '卡夫说R6打不过就是对面开挂'
</code></pre>

				</article>
				<div class="comments-wrap">
					<div class="share-comments">
						

						

						
					</div>
				</div><!-- end comments wrap -->
			</div>
		</div><!-- end columns -->
	</div><!-- end container -->
</section>  














<script src="asset/prism.js"></script>









</body>

</html>